package edu.ctbu.labtest.webapi;

import edu.ctbu.labtest.domain.Teacher;
import edu.ctbu.labtest.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/webapi/teacher")
public class TeacherRestController {

    @Autowired
    private TeacherService teacherService;

    /*读取老师数据*/
    @GetMapping("list")
    public List<Teacher> getAll(){
        List<Teacher> teachers = teacherService.findAll();
        return teachers;
    }

    /*通过id获取老师*/
    @PostMapping("/get/{id}")
    public Teacher get(@PathVariable Long id){
        Teacher teacher = teacherService.getById(id);
        teacher.setPassword("");
        return teacher;
    }

    /*新增老师的方法*/
    @PostMapping("/insert")
    public Teacher insert(Teacher teacher){
        Teacher teacher1 = teacherService.insert(teacher);
        return teacher1;
    }

    /*更新老师的方法*/
    @PutMapping("/update")
    public Teacher update(Teacher teacher){
        Teacher teacher1 = teacherService.update(teacher);
        return teacher1;
    }

    /*删除老师的方法*/
    @DeleteMapping("/delete")
    public void delete(Teacher teacher){
        teacherService.delete(teacher);
    }
}
